package Data::Conveyor::Ticket::Payload::Instruction::Factory;
# ptags: DCTPIF

# $Id: Factory.pm 11539 2006-05-24 11:44:03Z gr $

use warnings;
use strict;
use Error::Hierarchy::Util 'assert_defined';


our $VERSION = '0.02';


use base 'Class::Scaffold::Factory';


use constant INSTRUCTION_CLASS_FOR_NAME => (
    clear => 'Data::Conveyor::Ticket::Payload::Instruction::Clear',
);


sub gen_instruction {
    my ($self, $name, %args) = @_;
    assert_defined $name, 'instruction name';

    # Some instruction classes have a generic structure, they're called
    # Data::Conveyor::Ticket::Payload::Instruction::value_person_organization
    # and such. They're generated in Data::Conveyor::Environment, so they're
    # not in file, so we don't need to load_class() them.

    if (grep { $_ eq $name } $self->delegate->generic_instruction_classes) {
        my $class = $self->delegate->INSTRUCTION_CLASS_BASE() . '::' . $name;
        return $class->new(
            storage_type => $self->storage_type,
            %args
        );
    } else {

        # If it is not a generic value object instruction, go through the
        # normal way of generatic an object.

        return
            $self->gen_handler(INSTRUCTION_CLASS_FOR_NAME => [ $name ], %args);
    }
}


1;


__END__

{% USE p = PodGenerated %}

=head1 NAME

{% p.package %} - stage-based conveyor-belt-like ticket handling system

=head1 SYNOPSIS

    {% p.package %}->new;

=head1 DESCRIPTION

None yet. This is an early release; fully functional, but undocumented. The
next release will have more documentation.

=head1 METHODS

=over 4

{% p.write_methods %}

=back

{% p.write_inheritance %}

{% PROCESS standard_pod %}

=cut

